﻿//---弹窗方法
var TsingdaTips = {
    currentId: 10000,
    nextId: function () {
        ++this.currentId;
        return 'tsingdatips_' + this.currentId;
    },
    ask: function (options) {
        var defaults = {
            msg: '',//显示的弹出内容
            callback: null,//确定回调事件
            show_btn: true,//是否显示按钮
            show_btn_ok: true,
            show_btn_cancel: true,
            btn_ok_txt: '确定',//确定按钮文字
            btn_ok_cancel: '取消',//取消按钮文字
            show_close: true,//是否显示右上角关闭
            title: "提示"
        };
        options = options || {};
        var opts = jQuery.extend(defaults, options);
        var id = this.nextId();
        var html = '<div class="r_warnBox" style="width:276px;" id="' + id + '"><div class="r_warnBox_tit"><h3><strong>' + opts.title + '</strong></h3></div><div class="r_roomBoxContDel"><p class="alert">' + opts.msg + '</p>';
        //--------控制按钮--------
        if (opts.show_btn) {
            html += '<p class="confirm">';
            if (opts.show_btn_ok) {
                html += '<a class="sure" href="javascript:void(0);">' + opts.btn_ok_txt + '</a>';
            }
            if (opts.show_btn_cancel) {
                html += '<a class="cancel" href="javascript:$.fancybox.close();">' + opts.btn_ok_cancel + '</a>';
            }
            html += '</p>';
        }
        html += '</div>';
        if (opts.show_close) {
            html += '<a class="r_warnBox_close" href="javascript:$.fancybox.close();"></a>';
        }
        html += '</div>';
        //----显示浮层----
        $.fancybox(html, {
            padding: 0,
            scrolling: 'visible',
            closeBtn: false,
            modal: true
        });
        //----绑定事件----
        if (opts.show_close) {
            $('#' + id + ' .sure').one('click', function () {
                $.fancybox.close();
                if (opts.callback) {
                    opts.callback();
                }
            });
        }

    },
    alert: function (msg, callback) {
        //普通提示框
        var opts = {
            msg: msg,
            show_btn_cancel: false,
            callback: callback
        };
        this.ask(opts);
    },
    confirm: function (msg, callback, options) {
        //普通确认框
        var options = options || {};
        var opts = {
            msg: msg,
            callback: callback
        };
        opts = jQuery.extend(opts, options);
        this.ask(opts);
    },
    confirmRedirect: function (msg, url, opts) {
        //确认提示框并跳转
        this.confirm(msg, function () {
            location.href = url;
        }, opts);
    },
    redirect: function (msg, url) {
        //跳转框
        var html = '<div class="r_warnBox" style="width:276px;"><div class="r_warnBox_tit"><h3><strong>提示</strong></h3></div><div class="r_roomBoxContDel"><p class="alert">' + msg + '</p><p style="color:#999;font-weight: normal;font-size:12px;font-size: 10px;">正在跳转...</p></div></div>';
        $.fancybox(html, {
            padding: 0,
            scrolling: 'visible',
            closeBtn: false,
            modal: true,
            afterShow: function () {
                setTimeout(function () {
                    location.href = url;
                }, 800);
            }
        });
    }
};

/*
扩展方法
*/

//显示银行卡号
function displayBankNumber(number) {
    try {
        return number.substring(0, 4) + "**********" + number.substring(number.length - 4)

    } catch (e) {
        return number;
    }
}